package lesson.c4.sample;

import java.util.ArrayList;
import java.util.Scanner;

import lesson.c4.DataStore;

public class Main {
	
	public static void inputTest(){ 
		ArrayList<Student> sts = new ArrayList<Student>();
	    Scanner sc = new Scanner(System.in); 
	    System.out.println("初始化学生,请输入学生名：(输入end结束)");
	    String name = sc.nextLine();
	    int i = 0;
	    do{
	    	i++;
	    	if(name.equals("end") && i == 1){
	    		System.out.println("请至少输入一个学生名:");
	    		name = sc.nextLine();
	    	}
	    	if(name.equals("")){
	    		System.out.println("不能为空，请至少输入一个学生名:(输入end结束)");
	    		name = sc.nextLine();
	    	}
	    	sts.add(new Student(name));
	    	if(i >= 20) {
	    		name = "end";
	    	}else{
	    		System.out.println("请输入学生名:(输入end结束)");
		    	name = sc.nextLine();
	    	}
	    }while(!name.equals("end"));
	    
	    System.out.println("\n请输入课程数字：1=化学,2=物理,3=英语"); 
	    int sel = sc.nextInt();    //读取整型输入 
	    while(sel != 1 && sel != 2 && sel !=3){
	    	System.out.println("输入错误,重新输入"); 
	    	sel = sc.nextInt();
	    }
	    Course course = null;
	    switch(sel){
	    case 1: course = new Course("chemistry");break;
	    case 2: course = new Course("physics");break;
	    case 3: course = new Course("english");break;
	    default:break;
	    }
	    Student[] students = new Student[sts.size()];
	    for(i = 0 ; i < students.length; i++){
	    	students[i] = sts.get(i);
	    }
	    Group groupA = new Group(students);
	    Test cTest = new Test(groupA, course);
		cTest.doTest(); 

	    System.out.println("考试结束\n输入学生姓名查询成绩(输入end关闭系统):");
	    name = sc.nextLine();
	    name = sc.nextLine();
	    while(!name.equals("end")){
	    	int score = cTest.getStudentScore(name);
	    	if(score < 0){
				System.out.println(name + "学生成绩不存在");
			}else{
				System.out.println(course.name+"成绩:" + score);
			}
	    	System.out.println("\n输入学生姓名查询成绩(输入end关闭系统):");
	    	name = sc.nextLine();
	    }
	    
	    sc.close();
	}
	
	public static void autoTest(){
		Student[] students = new Student[20];
		for(int i = 0; i < students.length; i++){
			students[i] = new Student("学生"+i);
		}
		Group groupA = new Group(students);
		Course chemistry = new Course("chemistry");
//		Course physics = new Course("physics");
//		Course english = new Course("english");
		
		Test cTest = new Test(groupA, chemistry);
		cTest.doTest();
		int score = cTest.getStudentScore("学生1");
		if(score < 0){
			System.out.println("学生成绩不存在");
		}else{
			System.out.println(score);
		}
	}
	
	public static void main(String[] args) {
		DataStore.getInstance().reset();
		Main.inputTest();
	}
}
